** Define global path to the analysis/data subfolder
global path ""


** Merge border region identifiers
use "$path/labor_market/a31_borderid_mun2008.dta", clear

** Merge distance measures 
rename bfsnr municipality_cd
merge m:1 municipality_cd using "$path/labor_market/a41_traveltime_munnr2008.dta"
drop if _merge==2
rename _merge mergeDIST
rename municipality_cd bfsnr

merge m:1 munnr2012 using "$path/labor_market/a42_traveltime_munnr2012w.dta"
drop if _merge==2
drop _merge

** Fill up missing values of municipality classification 2008 with those from municpality classification in 2012
gen 	distmin = duration_bc_ww 	if mergeDIST==3
replace distmin = duration_bc_ww2	if mergeDIST==1
assert distmin!=.

*-----------------------------------------------------------------------------------
*** Time travel bin and time (period) interactions 
*-----------------------------------------------------------------------------------
gen 	bin15 = 1  if BR==1 & distmin<=15
replace bin15 = 2  if BR==1 & distmin>15 & distmin<=30
replace bin15 = 3  if BR==1 & distmin>30 
replace bin15 = 4  if BR==0 & distmin>30 // NOTE: needs to be above 30min to be consistent 

* Merge with sess data
merge 1:m bfsnr using "$path/labor_market/d4_sess_outcomesnat.dta"
save "$path/sess_merged.dta", 
